//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "ActualActual.h"
using namespace Cephei::QL::Times::Daycounters;
#include <gen/QL/Times/DayCounter.h>
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Times::Daycounters::CActualActual::CActualActual (Microsoft::FSharp::Core::FSharpOption<QL::Times::Daycounters::ActualActual::ConventionEnum>^ c) : CDayCounter(CActualActual::typeid)
{
    try
    {
#ifdef HANDLE
        _phActualActual = NULL;
#endif
        QuantLib::ActualActual::Convention _c = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Times::Daycounters::ActualActual::ConventionEnum>::IsSome::get (c) ? (QuantLib::ActualActual::Convention)c->Value : QuantLib::ActualActual::Convention::ISDA); //10
        _ppActualActual = new boost::shared_ptr<QuantLib::ActualActual> (new QuantLib::ActualActual ( _c ));
        SetDayCounter (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActualActual));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::Daycounters::CActualActual::CActualActual (boost::shared_ptr<QuantLib::ActualActual>& childNative, Object^ owner) : CDayCounter(CActualActual::typeid)
{
#ifdef HANDLE
	_phActualActual = NULL;
#endif
	_ppActualActual = &childNative;
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActualActual));
}
Cephei::QL::Times::Daycounters::CActualActual::CActualActual (QuantLib::ActualActual& childNative, Object^ owner) : CDayCounter(CActualActual::typeid)
{
#ifdef HANDLE
	_phActualActual = NULL;
#endif
	_ppActualActual = new boost::shared_ptr<QuantLib::ActualActual> (&childNative);
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActualActual));
    _ActualActualOwner = owner;
    _DayCounterOwner = owner;
}

Cephei::QL::Times::Daycounters::CActualActual::CActualActual (CActualActual^ copy) : CDayCounter(CActualActual::typeid)
{
#ifdef HANDLE
	_phActualActual = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppActualActual = new boost::shared_ptr<QuantLib::ActualActual> (copy->GetShared());
        _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActualActual));
    }
}
Cephei::QL::Times::Daycounters::CActualActual::CActualActual (System::Type^ t) : CDayCounter(CActualActual::typeid)
{
#ifdef HANDLE
	_phActualActual = NULL;
#endif
	if (!t->IsSubclassOf(CActualActual::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Times::Daycounters::CActualActual::CActualActual (QuantLib::Handle<QuantLib::ActualActual>& childNative, Object^ owner)  : CDayCounter(CActualActual::typeid)
{
	_phActualActual = &childNative;
	_ppActualActual = &static_cast<boost::shared_ptr<QuantLib::ActualActual>>(childNative.currentLink());
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActualActual));
    _ActualActualOwner = owner;
}
Cephei::QL::Times::Daycounters::CActualActual::CActualActual (QuantLib::Handle<QuantLib::ActualActual> childNative)  : CDayCounter(CActualActual::typeid)
{
	_phActualActual = &childNative;
	_ppActualActual = &static_cast<boost::shared_ptr<QuantLib::ActualActual>>(childNative.currentLink());
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActualActual));
}
#endif
#ifdef STRUCT
Cephei::QL::Times::Daycounters::CActualActual::CActualActual (QuantLib::ActualActual childNative)  : CDayCounter(CActualActual::typeid)
{
#ifdef HANDLE
	_phActualActual = NULL;
#endif
	_ppActualActual = new boost::shared_ptr<QuantLib::ActualActual> (new QuantLib::ActualActual (childNative));
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActualActual));
}
#endif

Cephei::QL::Times::Daycounters::CActualActual::~CActualActual ()
{
    if (_ppActualActual != NULL)
    {
	    delete _ppActualActual;
        _ppActualActual = NULL;
    }
}
Cephei::QL::Times::Daycounters::CActualActual::!CActualActual ()
{
    if (_ppActualActual != NULL)
    {
	    delete _ppActualActual;
    }
}
QuantLib::ActualActual& Cephei::QL::Times::Daycounters::CActualActual::GetReference ()
{
    if (_ppActualActual == NULL) throw gcnew NativeNullException ();
	return **_ppActualActual;
}
boost::shared_ptr<QuantLib::ActualActual>& Cephei::QL::Times::Daycounters::CActualActual::GetShared ()
{
    if (_ppActualActual == NULL) throw gcnew NativeNullException ();
	return *_ppActualActual;
}
QuantLib::ActualActual* Cephei::QL::Times::Daycounters::CActualActual::GetPointer ()
{
    if (_ppActualActual == NULL) throw gcnew NativeNullException ();
	return &**_ppActualActual;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ActualActual>& Cephei::QL::Times::Daycounters::CActualActual::GetHandle ()
{
	if (_phActualActual == NULL)
	{
		_phActualActual = new Handle<QuantLib::ActualActual> (*_ppActualActual);
	}
	return *_phActualActual;
}
#endif
bool Cephei::QL::Times::Daycounters::CActualActual::HasNative () 
{
	return (_ppActualActual != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Times::Daycounters::IActualActual^ Cephei::QL::Times::Daycounters::CActualActual_Factory::Create (Microsoft::FSharp::Core::FSharpOption<QL::Times::Daycounters::ActualActual::ConventionEnum>^ c)
{
    return gcnew CActualActual ( c);
}
